﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using AtletIS.Shared.Entities;
using AtletIS.Shared.Helpers;

namespace AtletIS.Shared.Forms
{
    public partial class frmStandardResults : Form
    {
        private int type = 0; // 1 - Start List, 2 - Results
        
        // Constructor
        public frmStandardResults(int type)
        {
            InitializeComponent();
            this.Icon = Properties.Resources.AtletIS64;
            this.type = type;
        }

        // Form Load
        private void frmCompleteResults_Load(object sender, EventArgs e)
        {
            this.lblTitle.Text = Globals.ActiveCompetition.Name;

            if (type == 1)
                this.Text = "Štartovná listina";

            if (type == 2)
                this.Text = "Výsledková listina";

            DisciplineListHelper.FillTreeView(this.tvDisciplines);
        }
        
        // Generate
        private void tsbGenerate_Click(object sender, EventArgs e)
        {
            if (type == 1)
            {
                StartListHelper.CompleteStartList(this.tvDisciplines);
            }

            if (type == 2)
            {
                ResultsHelper.bResultsWithSplitColumns = this.chkResultsWithSplitColumns.Checked;
                ResultsHelper.bResultsWithSplitTable = this.chkResultsWithSplitTable.Checked;
                ResultsHelper.bResultsWithSplitAsDiff = this.chkDiff.Checked;
                
                ResultsHelper.CompleteResults(this.tvDisciplines);
            }
        }

        // Check / uncheck all
        private void chkAll_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                foreach (TreeNode tn in tvDisciplines.Nodes)
                {
                    tn.Checked = chkAll.Checked;
                    foreach (TreeNode tnChild in tn.Nodes)
                    {
                        tnChild.Checked = chkAll.Checked;
                        foreach (TreeNode tnGrandchild in tnChild.Nodes)
                        {
                            tnGrandchild.Checked = chkAll.Checked;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHelper.ShowErrorInfo(ex);
            }
        }

        // Close
        private void tsbClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
